<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app"></div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.0-beta.7/vue.global.prod.min.js"></script>
<script>
  console.log(window);
  function random (n, m) {
    return parseInt(Math.random() * (m - n + 1) + n);
  }
  const app = Vue.createApp({
    template: `
      <div>
        <form @submit="add">
          <input placeholder="地点/餐品" v-model="food" required />
          <button type="submit">添加</button>  
        </form>
        <div>{{viewStr}}</div>
        <button @click="random">随机选择</button>
        <div>{{eat}}</div>
      </div>
    `,
    data: function () {

      return {
        message: 'app',
        list: ['面', '沙县', '食其家', '水饺', '粉', '铁男食堂', '凉皮'],
        food: '',
        eat: '',
      }
    },
    computed: {
      viewStr () {
        return this.list.join(' | ');
      }
    },
    methods: {
      add (ev) {
        this.list.push(this.food);
        this.food = '';
        ev.preventDefault();
      },
      random () {
        this.eat = this.list[random(0, this.list.length - 1)];
      }
    }
  });
  app.mount('#app');
</script>
</html>